﻿// //  ********************************************************************************
// //  Copyright (C) 2016 Sebastian Kenter. All rights reserved.
// // 
// //  Name    : PhotonServerProject | MasterServer | MasterServerModule.cs
// //  Created : 2016 - 03 - 22 16:52
// //  Modified: 2016 - 04 - 18 09:38
// //  ********************************************************************************

using Autofac;
using PhotonServerFramework.Implementation.Client;
using PhotonServerFramework.Implementation.Handler;
using PhotonServerFramework.Implementation.Handler.Forward;
using PhotonServerFramework.Implementation.Server;
using PhotonServerFramework.Interfaces.Application;
using PhotonServerFramework.Interfaces.Client;
using PhotonServerFramework.Interfaces.Handler;
using PhotonServerFramework.Interfaces.Server;

namespace MasterServer
{
    public class MasterServerModule : Module
    {
        /// <summary>
        ///     Override to add registrations to the container.
        /// </summary>
        /// <remarks>
        ///     Note that the ContainerBuilder parameter is unique to this module.
        /// </remarks>
        /// <param name="builder">
        ///     The builder through which components can be
        ///     registered.
        /// </param>
        protected override void Load(ContainerBuilder builder)
        {
            base.Load(builder);
            builder.RegisterType<MasterServer>().As<IServerApplication>().SingleInstance();
            builder.RegisterType<ClientPeerFactory>().As<IClientPeerFactory>().SingleInstance();
            builder.RegisterType<ServerPeerFactory>().As<IServerPeerFactory>().SingleInstance();
            builder.RegisterType<ClientPeerRegistry>().As<IClientPeerRegistry>().SingleInstance();
            builder.RegisterType<ServerPeerRegistry>().As<IServerPeerRegistry>().SingleInstance();
            builder.RegisterType<ServerHandlerRegistry>().As<IServerHandlerRegistry>().SingleInstance();
            builder.RegisterType<ClientHandlerRegistry>().As<IClientHandlerRegistry>().SingleInstance();
            builder.RegisterType<ClientRequestForwardHandler>().AsImplementedInterfaces();
            builder.RegisterType<ServerResponseForwardHandler>().AsImplementedInterfaces();
            builder.RegisterAssemblyTypes(ThisAssembly).Where(h => h.Name.EndsWith("Handler")).AsImplementedInterfaces();
        }
    }
}
